package com.nineclock.message.listener;

import cn.hutool.json.JSONUtil;
import com.nineclock.message.Service.MessageService;
import com.nineclock.message.pojo.NcMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "messagePushTopic", consumerGroup = "messagePushConsumer")
public class MsgConsumerListener implements RocketMQListener<NcMessage> {
    @Autowired
    private MessageService messageService;

    @Override
    public void onMessage(NcMessage message) {
        try {
            log.info("接收消息 , 调用极光服务 , 推送消息 : " + JSONUtil.toJsonStr(message));
            messageService.pushSingleMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}